
function Node(element){
    this.element = element
    this.next=null
}

function LList(){
    this.head=new Node("heade")
}

LList.prototype={
    //查找某个节点
    find:function(element){
        let currentNode=this.head
        while(currentNode.element!=element){
            currentNode=currentNode.next
        }
        return currentNode
    },
    //链表中插入新节点
    insert:function(newElement,item){
        let newNode=new Node(newElement)
        let current=this.find(item)
        newNode.next=current.next
        current.next=newNode
    },
    //查找某个节点的前一个节点
    findePreviuos:function(item){
        let currentNode=this.head
        while(!(currentNode.next ==null)&&(currentNode.next.element!=item)){
            currentNode=currentNode.next
        }
        return currentNode
    },
    //删除某个节点
    remove:function(item){
        let prevNode=this.findPrevious(item)
        if(!prevNode.next ==null){
            prevNode.next=prevNode.next.next
        }

    },
    //修改某一节点的数据
    edit:function(item,newItem){
        let element=this.find(item)
        element.element=newItem
    },
    //在控制台打印出所有节点
    display:function(){
        let currentNode=this.head
        while(!(currentNode.next==null)){
            console.log(currentNode.next.element)
            currentNode=currentNode.next
        }

    }












}

